import cTitle from "components/title";
import cMent from "components/ment";
import cGoodsList from "components/goodsList";
import { Toast } from "vant";

import cMyswipe from "components/myswipe";
import { Swipe, SwipeItem } from "components/meswipe";

import newcomerAward from "components/newcomer_award"; //新人奖
import teamName from "components/teamName";

//新装修
import top_navigation from "components/new_diy/top_navigation";
import U_article from "components/new_diy/article";
import U_backup from "components/new_diy/backup";
import U_blank from "components/new_diy/blank";
import U_button from "components/new_diy/button";
import U_community from "components/new_diy/community";
import U_coupons from "components/new_diy/coupons";
import U_cpssearch from "components/new_diy/cpssearch";
import U_cube from "components/new_diy/cube";
import U_deposit from "components/new_diy/deposit";
import U_form from "components/new_diy/form";
import U_goods from "components/new_diy/goods";
import U_goodscps from "components/new_diy/goodscps";
import U_goodsgroup from "components/new_diy/goodsgroup";
import U_ywmgroup from "components/new_diy/ywmgroup";
import U_goodsnearby from "components/new_diy/goodsnearby";
import U_goodsrush from "components/new_diy/goodsrush";
import U_goodstores from "components/new_diy/goodstores";
import U_goodsPackage from "components/new_diy/goodsPackage";
import U_headline from "components/new_diy/headline";
import U_homedata from "components/new_diy/homedata";
import U_line from "components/new_diy/line";
import U_livestreaming from "components/new_diy/livestreaming";
import U_location from "components/new_diy/location";
import U_lottery from "components/new_diy/lottery";
import U_maps from "components/new_diy/maps";
import U_notice from "components/new_diy/notice";
import U_richtext from "components/new_diy/richtext";
import U_search from "components/new_diy/search";
import U_staff from "components/new_diy/staff";
import U_shopfor from "components/new_diy/shopfor";
import U_shortvideo from "components/new_diy/shortvideo";
import U_signin from "components/new_diy/signin";
import U_simplegraph from "components/new_diy/simplegraph";
import U_slideshow from "components/new_diy/slideshow";
import U_stores from "components/new_diy/stores";
import U_storesranking from "components/new_diy/storesranking";
import U_suspendbutton from "components/new_diy/suspendbutton";
import U_tabcontrol from "components/new_diy/tabcontrol";
import U_title from "components/new_diy/title";
import U_video from "components/new_diy/video";
import U_foot from "components/new_diy/foot";
import U_moretabcontrol from "components/new_diy/multistageTab";
import U_selfpick from "components/new_diy/selfpick";
import U_wechatcode from "components/new_diy/wechatcode";
import U_bonuspool from "components/new_diy/bonusPoolsShow";
import U_lawyer from "components/new_diy/lawyer";
import U_couponStore from "components/new_diy/consumption/consumptionIndex";
import U_taskPackage from "components/new_diy/taskPackage";
import U_courseSupply from "components/new_diy/courseItem/courseList";
import U_integral from "components/new_diy/integral";
import U_travelAround from "components/new_diy/supplyChain/travelAround";
import U_yzSupplyCake from "components/new_diy/supplyChain/sachertorte";
import U_productAlbum from "components/new_diy/supplyChain/goodsAlbum";
import U_tiktokCps from "components/new_diy/supplyChain/TikTokCps";
import U_yzSupplyCamiloResources from "components/new_diy/supplyChain/ticketResources";
import U_unionCps from "components/new_diy/supplyChain/alliance";
import U_agentShop from "components/new_diy/agentShop/agentShop";
import U_newAuction from "components/new_diy/newAuction/newAuction";
import U_flashSaleCoupon from "components/new_diy/flashSaleCoupon/flashSaleCoupon";

window.firstAdvertisement = 1; //弹出周期设置为关闭网页(弹窗广告)
window.secondAdvertisement = 1; //弹出周期设置为关闭网页（全屏广告）

const documentElement = document.documentElement;
const body = document.body;
export default {
  data() {
    return {
      allowauth: 1, //会员等级浏览装修页权限
      home_default: "",
      posterShow: false,
      address: "",
      city: "",
      point: {},
      fullShow: false,
      timer: null,
      popShow: false,
      amout: false,
      follow_mode: {}, //引导关注
      category: [],
      goodsListData: [],
      ads: [],
      isfollow: false,
      pageinfo: "",
      isMiniApp: false,
      sliderNav: {},
      advertisement: {},
      isInDiy: 0,
      showNewcomerAward: false, //新人奖弹窗
      newcomerAward_data: {}, //新人奖活动信息

      isDecorate: false, //是否新装修
      clientWidth: "375",
      id: "M" + new Date().getTime(),
      advertising: {},
      full_screen: {},
      top_info: {},
      bottom_info: "",
      components: [],
      page_id: "",
      page_info: {},
      isBottom: false,
      btnFlag: false,

      current_page: 1,
      total_page: 0,
      isLoadMore: true,
      lastIndex: "",

      showPage: false,
      scrollTopTab: "",
      isInitVideoScrollFn: true, //true,则还未进行初始化，可触发initVideoScrollFn
      // 团队名称新增显示
      teamNameShow: false,
      member_team_title: ""
    };
  },
  beforeRouteEnter(to, from, next) {
    if (from.name === "goods" || from.name === "grab_group" || from.name === "newRetailSalesGood") {
      if (toGoodListIOS) {
        toGoodListIOS({ body: "toGoodListIOS" });
      }
    }
    next();
  },
  mounted() {
    localStorage.setItem("isset", 1);
    if (window.isMiniprogram) {
      this.isMiniApp = true;
    }
    window.HomeScrollTop = 0;
    // this.guideFollow();
  },
  beforeRouteLeave(to, from, next) {
    window.HomeScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    next();
  },
  deactivated() {
    clearTimeout(this.timer);
    this.timer = null;
    window.removeEventListener("scroll", this.debounce(this.handleScroll, 50));
  },
  activated() {
    this.isInitVideoScrollFn = true;
    this.posterShow = false;
    this.fullShow = false;
    this.popShow = false;
    this.advertisement = {};
    window.addEventListener("scroll", this.debounce(this.handleScroll, 50));

    if (this.fun.getPhoneEnv() == 3) {
      this.clientWidth = 375;
    } else {
      this.clientWidth = document.body.clientWidth;
    }

    if (window.__wxjs_environment === "miniprogram") {
      window.isMiniprogram = true;
    }
    if (window.isMiniprogram) {
      this.isMiniApp = true;
    }
    if (this.fun.getTyep() == 7) this.fun.setWXTitle(this.$store.state.temp.item.janst || "刷新中");

    try {
      wx.miniProgram &&
        wx.miniProgram.postMessage({
          data: { goods_title: this.$store.state.temp.item.janst }
        });
    } catch (error) {}

    this.sliderNav = this.$store.state.temp.item.topmenu;

    window.isInHome = 1; // 判断是否进入了首页
    if (!this.sliderNav && this.$store.state.temp.item.is_decorate !== 1) {
      this.sliderNav = {};
      this.check_url_query();
    } else if (window.isInDiy || window.HomeScrollTop == 0) {
      this.isInDiy = 1;
      window.isInDiy = 0;
      this.check_url_query();
    } else {
      if (window.location.href.indexOf("#/home?") > -1) {
        setTimeout(() => {
          window.scrollTo(0, window.HomeScrollTop);
        }, 200);
      }
    }
  },
  methods: {
    async check_url_query(){
      if(this.$route.query.zxg_id){ //指享购-url上有zxg_id参数则替换mid
       let {data} = await $http.post('plugin.zhixianggou.api.merchant.info',{id:this.$route.query.zxg_id});
       if(data.member_id){
          let _link = `${this.fun.getSiteRoot()}/addons/yun_shop/?menu#/home?i=${this.fun.getKeyByI()}&mid=${data.member_id}`;
          window.history.replaceState('', '', _link);
       }
      }
      this.tempInfo();
    },
    getParams() {
      let that = this;
      let _url = document.location.href;
      // 要用post  链接太长
      $http
        .post("home-page.get-params", { url: _url }, " ")
        .then(response => {
          if (response.result === 1) {
            if (this.showNewcomerAward) {
              if (response.data.advertisement && response.data.advertisement.advertisement) {
                this.advertisement = response.data.advertisement.advertisement;
              }
            } else {
              if (window.isDecorate) {
                if (this.advertising && this.advertising.id) {
                  let _showPopRule_1 = window.firstAdvertisement === 1 && this.advertising.show_rule === 1;//每次进入页面
                  let _showPopRule_2 = false;
                  if(this.advertising.show_rule === 3) {
                    const today = new Date().toLocaleDateString();//获取当前日期
                    const ADPopflag = localStorage.getItem('AdDisplayedDate');//获取记录下来的日期
                    _showPopRule_2 = ADPopflag !== today;//每日H5首页弹窗一次
                    localStorage.setItem('AdDisplayedDate', today);
                  }

                  if(_showPopRule_1 || _showPopRule_2){
                    window.firstAdvertisement = 0;
                    this.popShow = true;
                    this.$nextTick(() => {
                      this.initAdvertising();
                    });
                  }
                }
              } else {
                // this.$route.meta.foot = false;
                // this.$emit("changeFoot", this.$route.meta.foot);
              }
            }
            // 刷新页面时，在这刷新顶部菜单栏
            this.sliderNav = this.$store.state.temp.item.topmenu ? this.$store.state.temp.item.topmenu : {};

            this.guideFollow(response.data.guide);
            this.pluginHandle();//处理插件的
          } else {
            if (response.msg == "站点已关闭") {
              that.$dialog.alert({ message: response.msg });
            }
            console.log(response.msg);
          }
        })
        .catch(err => {
          console.error(err, "app");
        });
    },
    childTeam() {
      this.teamNameShow = false;
    },
    // 获取装修或者是默认的数据
    tempInfo(extinfo = {}) {
      let that = this;
      let _params = { ...extinfo };
      let adcode = JSON.parse(window.localStorage.getItem("myLocation"))?.addressComponent?.adcode||null;//城市关联装修页面
      if(Number(adcode) > 0 ) _params.address_code = adcode;
      if(Number(extinfo.address_code) > 0) _params.address_code = extinfo.address_code;
      // let adcode = window.localStorage.getItem("CityPageADCode")||null;//城市关联装修页面
      // if(adcode && _params.address_code) _params.address_code = adcode;
      this.showPage = false;
      $http.get("home-page.index", _params, "加载中").then(
        response => {
          if (!response) return;
          if (response.result === 1) {
            this.showPage = true;
            this.page_info = response.data.item.page_info;
            if (this.fun.isCPS() && this.fun.isCPSAPPI()) {
              // cpsApp环境下，app调用原生设置导航栏颜色
              let cpsNavTheme = { 'preview_color': this.page_info?.webNav_preview_color || '#ffffff', 'font_color': this.page_info?.webNav_font_color || '#000000' };
              try {
                if (this.fun.isIosOrAndroid() === "android") {
                  themeColorAndroid(JSON.stringify(cpsNavTheme));
                } else {
                  themeColorIOS({ body: "themeColorIOS", json: JSON.stringify(cpsNavTheme) });
                }
              } catch (error) {
                console.log(error);
              }
            }
            this.showNewcomerAward = false;
            this.newcomerAward_data = {};
            if(this.$route.query.device_no){//生态圈饮水机-设备号
              window.localStorage.setItem('device_no',this.$route.query.device_no)
            }
            try {
              if (response.basic_info) {
                // 有basic_info
                this.teamNameShow = response.basic_info.globalParameter && response.basic_info.globalParameter.member_team ? true : false;
                this.member_team_title = response.basic_info.globalParameter && response.basic_info.globalParameter.member_team ? response.basic_info.globalParameter.member_team : "";
                console.log(this.teamNameShow);
              } else {
                // 没有basic_info就去缓存看下
                let yz_basic_info = JSON.parse(localStorage.getItem("yz_basic_info"));
                this.teamNameShow = yz_basic_info.globalParameter && yz_basic_info.globalParameter.member_team ? true : false;
                this.member_team_title = yz_basic_info.globalParameter && yz_basic_info.globalParameter.member_team ? yz_basic_info.globalParameter.member_team : "";
              }
              //第一次进入首页并带参数basic_info，并符合新人奖条件
              if (response.basic_info && response.basic_info.home.plugin && response.basic_info.home.plugin.new_member_prize) {
                this.newcomerAward_data = response.basic_info.home.plugin.new_member_prize;
              }
            } catch (err) {
              console.log(err);
            }
            try {
              //第一次不是进入首页但符合新人奖条件，返回首页后显示
              let _new_member_prize = JSON.parse(window.localStorage.getItem("new_member_prize"));
              if (_new_member_prize && !this.fun.isTextEmpty(_new_member_prize.prize)) {
                this.showNewcomerAward = true;
              }
            } catch (err) {
              console.log(err);
            }

            if (response.basic_info && !this.fun.isTextEmpty(this.newcomerAward_data.prize)) {
              //第一次进入首页并带参数basic_info，并符合新人奖条件
              // this.newcomerAward_data = response.basic_info.home ? response.basic_info.home.plugin.new_member_prize : {}
              this.showNewcomerAward = true;
            }
            // else if (!this.fun.isTextEmpty(response.data.plugin.new_member_prize) && !this.fun.isTextEmpty(response.data.plugin.new_member_prize.prize)) {
            //   //有多个新人奖活动，不是第一次领取新人奖
            //   this.newcomerAward_data = response.data.plugin.new_member_prize;
            //   this.showNewcomerAward = true;
            // }
            else if (this.showNewcomerAward) {
              //第一次不是进入首页但符合新人奖条件，返回首页后显示
              this.newcomerAward_data = JSON.parse(window.localStorage.getItem("new_member_prize"));
            }
            if (window.location.href.indexOf("#/home?") > -1 && that.isInDiy == 1) {
              // diy页面返回首页，也要跳转到记录的高度
              setTimeout(() => {
                window.scrollTo(0, window.HomeScrollTop);
              }, 200);
            }
            that.isInDiy = 0;
            if (!response.data.default) {
              this.page_id = response.data.item.id;
              if (response.data.item.page) {
                this.total_page = response.data.item.page.total_page;
                this.current_page = response.data.item.page.current_page;
                this.lastIndex = response.data.item.page.count - 1;
                this.isLoadMore = true;
              }

              let needLocations = ["U_location", "U_stores", "U_goodsnearby", "U_community", "U_homedata", "U_storesranking", "U_goodstores"];//需要定位权限的组件
              // this.$store.commit("setNewDiyData", response.data.item);
              response.data.item.janst =
                response.data.item.page_info && response.data.item.page_info.page_title
                  ? response.data.item.page_info.page_title
                  : this.$store.state.temp.mailInfo
                  ? this.$store.state.temp.mailInfo.name
                  : "商城";

              this.components = response.data.item.datas;
              if (this.components && this.components.length > 0) {
                for(let item of this.components){
                  if(item.component_key == 'U_newBlindBox'){
                    // 设置了新盲盒，跳转到盲盒首页链接
                    this.$router.push(this.fun.getUrl("newBlindBox", {}, {}));
                    break;
                  }
                  if (needLocations.includes(item.component_key)) {
                    if (YDB) {
                      //云打包APP调用SDK获取地理位置
                      YDB.GetGPS("DoWithYDBGPS");
                      //云打包APP调用SDK获取手机设备uid
                      YDB.GetDeviceInformation("senduid");
                    }
                    this.isLocation = true;
                    break;//中止循环
                  }
                }
              }

              // if (this.isLocation) {
              // 组件里面已经有定位
              //   this.fun.getLocation();
              // }

              if (response.data.item.page_info) {
                //弹窗广告
                this.advertising = response.data.item.page_info.advertising_id || {};
                if (this.advertising.id && this.advertising.datas) {
                  this.advertising.datas = JSON.parse(this.advertising.datas);
                }

                // 全屏广告
                this.full_screen = response.data.item.page_info.full_screen_id || {};
              }

              //弹窗广告
              this.getParams();

              if (this.full_screen && this.full_screen.id) {
                let _showFullRule_1 = window.secondAdvertisement === 1 && this.full_screen.show_rule === 1;//每次进入页面
                let _showFullRule_2 = false;
                if(this.full_screen.show_rule === 3) {
                  const fullToday = new Date().toLocaleDateString();//获取当前日期
                  const ADFullflag = localStorage.getItem('AdFullDisplayedDate');//获取记录下来的日期
                  _showFullRule_2 = ADFullflag !== fullToday;//每日H5首页弹窗一次
                  localStorage.setItem('AdFullDisplayedDate', fullToday);
                }

                if(_showFullRule_1 || _showFullRule_2){
                  window.secondAdvertisement = 0;
                  this.fullShow = true;
                  this.countDown(this.full_screen.show_time);
                }
              }

              if (response.data.item.top && response.data.item.top.id) {
                this.top_info = JSON.parse(response.data.item.top.page_info);
              }

              if (this.fun.isCPS() && this.fun.isCPSAPPI() && response.data.item.cps_foot_type) {
                if (response.data.item.cps_foot_type == -1) {
                  // 不显示
                  this.bottom_info = "";
                } else if (response.data.item.cps_foot_type == 1) {
                  // 显示默认
                  if (!response.data.item.foot) {
                    // 显示系统默认
                    this.bottom_info = {
                      defaultData: true
                    };
                  } else {
                    // 显示列表设置的默认
                    if (response.data.item.foot && response.data.item.foot.page_info) {
                      this.bottom_info = JSON.parse(response.data.item.foot.page_info);
                    } else {
                      this.bottom_info = {
                        defaultData: true
                      };
                    }
                  }
                } else if (response.data.item.cps_foot_type == 2) {
                  // 显示自定义的底部导航
                  if (response.data.item.foot && response.data.item.foot.id) {
                    this.bottom_info = JSON.parse(response.data.item.foot.page_info);
                  }
                }
              } else {
                // 首页的底部有三种情况
                if (response.data.item.foot_type == -1) {
                  // 不显示
                  this.bottom_info = "";
                } else if (response.data.item.foot_type == 1) {
                  // 显示默认
                  if (!response.data.item.foot) {
                    // 显示系统默认
                    this.bottom_info = {
                      defaultData: true
                    };
                  } else {
                    // 显示列表设置的默认
                    if (response.data.item.foot && response.data.item.foot.page_info) {
                      this.bottom_info = JSON.parse(response.data.item.foot.page_info);
                    } else {
                      this.bottom_info = {
                        defaultData: true
                      };
                    }
                  }
                } else if (response.data.item.foot_type == 2) {
                  // 显示自定义的底部导航
                  if (response.data.item.foot && response.data.item.foot.id) {
                    this.bottom_info = JSON.parse(response.data.item.foot.page_info);
                  }
                }
              }

              this.isDecorate = true;
            } else {
              this.home_default = response.data.default || {};
              response.data.item.janst = this.$store.state.temp.mailInfo.name;
              //弹窗广告
              this.getParams();
            }
            // this.$store.commit("tempIndex", response.data);
            // window.localStorage.setItem("tempIndex", JSON.stringify(response.data));  存vuex里不存localStorage
            this.fun.setWXTitle(response.data.item.janst || "欢迎使用");
            if(this.fun.isXueXiApp()) {
              document.title = response.data.item.janst;
            }
            // this.$store.commit("setWatchDiypage", response.data.item.pageinfo.params.allowauth);
            this.allowauth = response.data.item.pageinfo.params.allowauth;
            this.initShare_v2();
            if (response.data.item.pageinfo.params.allowauth == 0 && response.data.item.page_info.member_level_url && response.data.item.page_info.member_level_url.link) {
              this.timer = setTimeout(() => {
                clearTimeout(this.timer);
                window.location.href = response.data.item.page_info.member_level_url.link;
              }, 3000);
            }
          } else {
            that.$dialog.alert({ message: response.msg });
          }
        },
        response => {
          console.log(response);
        }
      );
    },
    getMoreDecorate() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.current_page < this.total_page) {
        this.current_page = this.current_page + 1;
        $http.get("plugin.decorate.frotend.decorate-api.get-page", { decorate_page: this.current_page, decorate_id: this.page_id }, "..").then(response => {
          if (response.result == 1) {
            this.isLoadMore = true;
            this.components = this.components.concat(response.data.datas);
          } else {
            this.isLoadMore = false;
            this.current_page = this.current_page - 1;
          }
        });
      } else {
        console.log("加载完了");
      }
    },
    // 图片加载完回调
    getImg(url, callback) {
      let img = new Image();
      img.src = url;
      //如果图片被缓存，则直接返回缓存数据
      if (img.complete) {
        /* callback(img.width, img.height); */
        callback(Number(img.height) / Number(img.width));
      } else {
        //完全加载完毕的事件
        img.onload = function() {
          /* callback(img.width, img.height); */
          callback(Number(img.height) / Number(img.width));
        };

        img.onerror = function() {
          console.log("图片加载出错");
        };
      }
    },
    onClickADUrl() {
      if (this.fun.isCPS()) {
        // cpsApp环境下，app调用原生跳转小程序方法
        let json = {
          mini_route: this.advertising.s_url,
          mini_id: this.advertising.s_id
        };
        if (this.fun.isIosOrAndroid() === "ios") {
          miniWXIOS({ body: "miniWXIOS", json: JSON.stringify(json) });
        } else {
          miniWXAndroid(JSON.stringify(json));
        }
        return;
      }
    },
    initAdvertising() {
      let that = this;
      this.getImg(this.advertising.image, function(scale) {
        // 图片加载完后获取图片高度
        let script = document.createElement("script");
        script.type = "text/wxtag-template";
        script.text = `<div style="width: ${that.clientWidth * 0.65}px;height: ${that.clientWidth * 0.65 * scale}px;"></div>`;
        that.advertising.html = `<wx-open-launch-weapp username="${that.advertising.s_id}" path="${that.advertising.s_url}">${script.outerHTML}</wx-open-launch-weapp>`;
        that.$forceUpdate();
      });
    },
    toatten() {
      if (this.follow_mode.type == "1") {
        window.location.href = this.follow_mode.url;
      } else {
        this.posterShow = true;
      }
    },
    cloneNewcomerAward(data) {
      // this.$store.commit("setNewcomerAward", false);
      window.localStorage.removeItem("new_member_prize");
      this.showNewcomerAward = false;
      if (data) {
        window.location.href = data;
        return;
      }
      if (this.advertisement) {
        this.getAdvertise(this.advertisement);
      } else if (this.advertising) {
        if (this.advertising && this.advertising.id && window.firstAdvertisement === 1) {
          window.firstAdvertisement = 0;
          this.popShow = true;
          this.$nextTick(() => {
            this.initAdvertising();
          });
        }
      } else {
        // this.$route.meta.foot = false;
        // this.$emit("changeFoot", this.$route.meta.foot);
      }
    },
    //关注方法
    guideFollow(data) {
      // $http.get("member.member.guideFollow").then(
      //   response => {
      if (data) {
        this.isfollow = true;
        this.follow_mode = data;
      } else {
        this.follow_mode = false;
      }
      //   },
      //   response => {
      //     console.log(response.msg);
      //   }
      // );
    },
    tosearch() {
      this.$router.push(this.fun.getUrl("search", { fromHome: 1 }));
    },
    //获取滚动条当前的位置
    getScrollTop() {
      var scrollTop = 0;
      if (documentElement && documentElement.scrollTop) {
        scrollTop = documentElement.scrollTop;
      } else if (body) {
        scrollTop = body.scrollTop;
      }
      return scrollTop;
    },
    //获取当前可视范围的高度
    getClientHeight() {
      var clientHeight = 0;
      if (body.clientHeight && documentElement.clientHeight) {
        clientHeight = Math.min(body.clientHeight, documentElement.clientHeight);
      } else {
        clientHeight = Math.max(body.clientHeight, documentElement.clientHeight);
      }
      return clientHeight;
    },
    //获取文档完整的高度
    getScrollHeight() {
      return Math.max(body.scrollHeight, documentElement.scrollHeight);
    },
    debounce(fn, delay) {
      let last, deferTimer;
      return function(args) {
        let that = this;
        let _args = arguments;
        let now = +new Date();
        if (last && now < last + delay) {
          clearTimeout(deferTimer);
          deferTimer = setTimeout(function() {
            last = now;
            fn.apply(that, _args);
          }, delay);
        } else {
          last = now;
          fn.apply(that, _args);
        }
      };
    },
    handleScroll() {
      var top = document.documentElement.scrollTop || document.body.scrollTop;
      top < 50 ? (this.amout = false) : (this.amout = true);
      this.scrollTopTab = top;
      let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
      if (scrollTop > 60) {
        this.btnFlag = true;
      } else {
        this.btnFlag = false;
      }
      //滚动事件触发
      if (Number(this.getScrollTop() + this.getClientHeight() + 105) >= this.getScrollHeight() && this.$route.name === "home") {
        if (this.isLoadMore) {
          this.getMoreDecorate();
        }
        //此处发起请求
        this.isBottom = true;
      } else {
        this.isBottom = false;
      }

      this.videoScrollHandle(); //监听处理视频组件逻辑
    },
    videoScrollHandle() {
      //监听处理视频组件，当视频组件不在可视区时，视频暂停播放，且暂停页面渲染
      // const runInArr = [];
      if (!this.$refs.U_video) {
        return;
      }
      const videoRefArr = this.$refs.U_video || [];
      videoRefArr.forEach((item, index) => {
        const offset = item.$el.getBoundingClientRect();
        const offsetTop = offset.top + 200;
        const offsetBottom = offset.bottom;
        if (offsetTop - 200 <= window.innerHeight && offsetBottom >= 0) {
          item.showComponent(); //进入可视区域
        } else {
          item.pauseFn(); //移出可视区域，暂停视频
        }
      });
    },
    pauseVideoOther(_id) {
      //只保留当前点击的视频播放，暂停其他视频的播放
      if (!this.$refs.U_video) {
        return;
      }
      const videoRefArr = this.$refs.U_video || [];
      videoRefArr.forEach((item, index) => {
        if (item.id != _id) item.pauseFn();
      });
    },
    initVideoScrollFn() {
      this.$nextTick(() => {
        this.videoScrollHandle();
      });
    },
    //banner点击
    bannerClick(item) {
      if (!this.fun.isTextEmpty(item.link)) {
        window.location.href = item.link; //跳转
      }
    },

    //旧装修--方法--开始
    gotoBrand(item) {
      this.$router.push(this.fun.getUrl("brandgoods", { id: item.id, fromHome: 1 }));
    },
    gotoTimeGood(val) {
      this.$router.push(this.fun.getUrl("goods", { id: val }));
    },
    gotoAdvs(link) {
      if (!this.fun.isTextEmpty(link)) {
        window.location.href = link; //跳转
      }
    },
    //显示首屏广告和弹窗广告
    getAdvertise(data) {
      if (data) {
        this.advertisement = data;

        if (this.advertisement.Midswitch) {
          if (this.advertisement.Midrule === 0 && window.firstAdvertisement === 1) {
            this.popShow = true;
            window.firstAdvertisement = 0;
          }
        }

        if (this.advertisement.switch) {
          if (this.advertisement.rule === 0 && window.secondAdvertisement === 1) {
            // this.$route.meta.foot = true;
            this.fullShow = true;
            // this.$emit("changeFoot", this.$route.meta.foot);
            this.countDown(this.advertisement.time);
            window.secondAdvertisement = 0;
          } else {
            // this.$route.meta.foot = false;
            // this.$emit("changeFoot", this.$route.meta.foot);
          }
        } else {
          // this.$route.meta.foot = false;
          // this.$emit("changeFoot", this.$route.meta.foot);
        }
      } else {
        // this.$route.meta.foot = true;
        // this.$emit("changeFoot", this.$route.meta.foot);
      }
    },
    close() {
      this.fullShow = false;
    },
    closePop() {
      this.popShow = false;
    },
    countDown(num) {
      this.full_screen.show_time = num;
      this.advertisement.time = num;
      --num;
      this.timer = setTimeout(() => {
        if (num <= 0) {
          this.fullShow = false;
          // this.$route.meta.foot = false;
          // this.$emit("changeFoot", this.$route.meta.foot);
        } else {
          this.countDown(num);
        }
      }, 1000);
    },
    turnTo() {
      if (this.advertisement.link) {
        if (this.advertisement.link === window.location.href) {
          this.popShow = false;
        } else {
          window.location.href = this.advertisement.link;
        }
      }
    },

    turnFullTo() {
      if (this.full_screen.h_url) {
        if (this.full_screen.h_url !== window.location.href) {
          window.location.href = this.full_screen.h_url;
        }
      }
    },
    turnTo2() {
      if (this.advertising.h_url) {
        if (this.advertising.h_url === window.location.href) {
          this.popShow = false;
        } else {
          window.location.href = this.advertising.h_url;
        }
      }
    },
    refreshComponent(e) {
      // console.log("有子组件触发", e);
      if (e) {
        if (e.type == "selfpick") {
          this.initShare_v2();
        } else if (e.type == "video") {
          this.pauseVideoOther(e.id); //只保留当前点击的视频播放，暂停其他视频的播放
        } else if (e.type == "initVideo") {
          if (this.isInitVideoScrollFn) {
            this.isInitVideoScrollFn = false;
            this.initVideoScrollFn(); //isInitVideoScrollFn为true,则还未进行初始化，触发initVideoScrollFn，判断视频位置
          }
        }
      }
    },
    initShare_v2() {
      if (this.page_info.page_title && window.isDecorate) {
        //新装修
        this.fun.wxShare(
          "",
          { mid: this.fun.getKeyByMid() },
          {
            title: this.page_info.page_title || null,
            imgUrl: this.page_info.page_icon || null,
            description: this.page_info.page_description || null
          },
          () => {},
          () => {
            for (let i = 0; i < this.components.length; i++) {
              if (this.components[i].component_key == "U_lottery") {
                this.getShare(this.components[i].remote_data.lottery.id);
              }
            }
          }
        );
      } else {
        this.fun.wxShare(
          "",
          {},
          {},
          () => {},
          () => {
            for (let i = 0; i < this.components.length; i++) {
              if (this.components[i].component_key == "U_lottery") {
                this.getShare(this.components[i].remote_data.lottery.id);
              }
            }
          }
        );
      }
    },
    getShare(id) {
      $http
        .post("plugin.lucky-draw.frontend.draw.getShare", { lotteryId: id })
        .then(response => {
          if (response.result === 1) {
            console.log(response);
          }
        })
        .catch(error => {});
    },
    pluginHandle(){
      this.plugin_setting = JSON.parse(localStorage.getItem("plugin_setting"))||{};
      let { quicken_income } = this.plugin_setting;
      if(quicken_income?.dialog && quicken_income?.dialog?.show_dialog) {
        this.$dialog.alert({ message: quicken_income.dialog.dialog_text });
      }
    },
    // componentMenuOpen(e) {
    //   this.setData({
    //     showDropdownMenu: e.detail
    //   });
    // },
    // componentMenuClose(e) {
    //   this.setData({
    //     showDropdownMenu: e.detail
    //   });
    // }
  },

  components: {
    cTitle,
    cMent,
    cGoodsList,
    cMyswipe,
    Swipe,
    SwipeItem,
    newcomerAward,
    teamName,

    //新装修
    top_navigation,
    U_article,
    U_backup,
    U_blank,
    U_button,
    U_community,
    U_coupons,
    U_cpssearch,
    U_cube,
    U_deposit,
    U_form,
    U_goods,
    U_goodscps,
    U_goodsgroup,
    U_goodsnearby,
    U_goodsrush,
    U_goodstores,
    U_goodsPackage,
    U_headline,
    U_homedata,
    U_line,
    U_livestreaming,
    U_location,
    U_lottery,
    U_maps,
    U_notice,
    U_newNotice: () => import("components/new_diy/newNotice"),
    U_richtext,
    U_search,
    U_staff,
    U_shopfor,
    U_shortvideo,
    U_signin,
    U_simplegraph,
    U_slideshow,
    U_stores,
    U_storesranking,
    U_suspendbutton,
    U_tabcontrol,
    U_title,
    U_video,
    U_foot,
    U_moretabcontrol,
    U_selfpick,
    U_wechatcode,
    U_bonuspool,
    U_scanpicture: () => import("components/new_diy/U_scanpicture"),
    U_ywmgroup,
    U_lawyer,
    U_bottomSuspendButton: () => import("@/components/new_diy/bottomSuspendButton.vue"),
    U_couponStore,
    U_taskPackage,
    U_courseSupply,
    U_integral,
    U_travelAround,
    U_yzSupplyCake,
    U_productAlbum,
    U_tiktokCps,
    U_yzSupplyCamiloResources,
    U_unionCps,
    U_businessCard: () => import("@/components/new_diy/businessCard.vue"),
    U_mapMarker: () => import("@/components/new_diy/mapMarker.vue"),
    U_assistCompetitionVote: () => import("@/components/new_diy/assist-competition-vote.vue"),
    U_assistCompetition: () => import("@/components/new_diy/assist-competition.vue"),
    U_calcVal: () => import("@/components/new_diy/calcVal.vue"),
    U_agentShop,
    U_newAuction,
    U_flashSaleCoupon,
    cloud_shop_popup : ()=> import("@/components/new_diy/cloud-shop/cloud_shop_popup"),
    // 云店装修
    U_cloudShopBrand:()=> import("@/components/new_diy/cloud-shop/special_subject.vue"),
    U_NComerZone : ()=> import("@/components/new_diy/cloud-shop/cloud_shop_popup.vue"),
    U_NComerUpgrade : ()=> import("@/components/new_diy/cloud-shop/cloud_shop_popup.vue"),
    U_Bartending: ()=> import("@/components/new_diy/bartending.vue"),
    U_returnPoint: ()=> import("@/components/new_diy/return-point/returnPoint.vue"),
    U_jdSupply: ()=> import("@/components/new_diy/jdSupply.vue"),
  }
};
